
/** @file monte_carlo.h
 *
 * Interface to monte_carlo
 *
 */

/*
 *  Copyright (C) 2007 Stefan Weinzierl
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __SECTOR_DECOMPOSITION_MONTE_CARLO_H__
#define __SECTOR_DECOMPOSITION_MONTE_CARLO_H__

#include <cstddef>

#include <ginac/ginac.h>

namespace sector_decomposition {

  /**
   *
   * This class defines the parametes for the Monte Carlo integration.
   *
   * The Monte Carlo integration uses first iterations_low iterations with calls_low function
   * evaluations to set up a grid for the Vegas algorithm.
   * The results from this first phase (apart from the grid) are discarded.
   *
   * In the second stage, the integrand is evaluated in iterations_high iterations with calls_high
   * function evaluations each.
   *
   */
  class monte_carlo_parameters {

    // ctors
    public :  
      monte_carlo_parameters(void);
      monte_carlo_parameters(size_t iterations_low, size_t iterations_high, size_t calls_low, size_t calls_high);

      // member variables :
    public :
      /// number of iterations to warm-up the grid
      size_t iterations_low;
      /// number of iterations for the Monte-Carlo integration
      size_t iterations_high;

      /// number of integrand evaluations for one iteration during the warm-up phase
      size_t calls_low;
      /// number of integrand evaluations for one iteration during the Monte-Carlo integration
      size_t calls_high;
  };

  /**
   *
   * This class defines the return type of the result 
   * of a Monte Carlo integration.
   *
   * This class holds the Monte Carlo estimate for the integral (mean), the Monte Carlo integration
   * error (error) and the \f$ \chi^2 \f$ (chi_squared).
   *
   */
  class monte_carlo_result {

	// ctors
    public :  
      monte_carlo_result(void);
      monte_carlo_result(double mean, double error, double chi_squared);

	// functions 
    public :
      double get_mean(void) const;
      double get_error(void) const;
      double get_chi_squared(void) const;

	// member variables :
    protected : 
      /// Monte-Carlo estimate for the integral
      double mean;
      /// Monte-Carlo error
      double error;
      /// chi-squared for the Monte-Carlo integration
      double chi_squared;
  };

  /**
   *
   * The entry point for the Monte Carlo integration.
   *
   */
  monte_carlo_result intnum(GiNaC::ex expr, const std::vector<GiNaC::ex> & x, const std::vector<double> & xmin, const std::vector<double> & xmax, const monte_carlo_parameters & mc_parameters, int verbose_level = 0);

  /**
   *
   * A simplified entry point for the Monte Carlo integration, where the integration is over the hypercube.
   *
   */
  monte_carlo_result intnum(GiNaC::ex expr, const std::vector<GiNaC::ex> & x, const monte_carlo_parameters & mc_parameters, int verbose_level = 0);

  /**
   *
   * The implementation of the Monte Carlo integration.
   *
   */
  monte_carlo_result intnum_imp(GiNaC::ex expr, size_t dimension, double *xmin, double *xmax, const monte_carlo_parameters & mc_parameters, int verbose_level = 0);

} // namespace sector_decomposition

#endif // ndef __SECTOR_DECOMPOSITION_MONTE_CARLO_H__

